<?php
#
# author: Phil Spagnolo & Cody Sorgenfrey
# (c)2012 South Hill Calvary Chapel
#

include_once("../mysql/database_info.php");
include_once("common.php");
include_once("../mysql/common.php");
connect_select_test("servants");
function ministry_info($title, $link_names, $links, $schedule) 
{
	$a = count($link_names);
	$b = count($links);
	if ($a != $b) {
		die ("Error:  The link_names and links array must be the same length.");
		return;
	}
	printf("<h4>\n");
	printf("\t%s\n",$title);
	printf("</h4>\n");
	printf("<p>\n");
	printf("\t<ul>\n");
	if ($schedule) {
		printf("\t\t<li>\n");
		printf("\t\tSchedule:  \n");
		mFindSchedules($schedule);
		printf("\t\t</li>\n");
	}
	for ($i=0; $i < $b; $i++) {
		printf("\t\t<li>\n");
		printf("<a href='%s' target='_blank'>[%s]</a>\n", 
		     $links[$i], $link_names[$i]);
		printf("\t\t</li>\n");
	}
	printf("\t\t</ul>\n");
	printf("</p>\n");
}
function printBlock($name)
{
	$blockResult = mysql_query("SELECT * FROM `servants` WHERE `name`='$name'");
	while ($info = mysql_fetch_array($blockResult)) {
		printf("<div class='paragraph'>%s</div>\n", $info['description']);
		$link_names = explode("\n", $info['titles']);
		$links = explode("\n", $info['links']);
		if ($link_names[0] != null){
			ministry_info($name, $link_names, $links, $info['DBTag']); 
		} else {
			ministry_info($name, null, null, $info['DBTag']);
		}
	}
}
$title = "Servants"; 
$meta_key= 'servants, serve, resources, info, schedules, ministries';
$meta_desc= "A list of resources for serving at South Hill Calvary Chapel";
$morehtml= NULL;
$morejava= NULL;
startPage($title, $meta_key, $meta_desc, $morehtml, $morejava);
$greeting = mysql_fetch_array(mysql_query("SELECT * FROM `servants` WHERE `name`='Greeting'"));
printf("<h5>%s</h5>", $greeting['description']);
$pageContentResult = mysql_query("SELECT * FROM `servants` WHERE `name`!='Greeting' ORDER BY `name` ASC");
while ($pageContent = mysql_fetch_array($pageContentResult)){
	printBlock($pageContent['name']);
}
endPage();
?>